<?php
class video extends CI_Model{

	function get_video($id = NULL, $user_id = NULL, $limit=NULL, $offset=0, $private=NULL){
		$this->db->select('video.*, alumni.nama as username');
		$this->db->from('video');
		$this->db->join('alumni','alumni.id_user=video.id_user');
		if($id != NULL){
			$this->db->where('video.id_video', $id);
		}
		if($user_id != NULL){
			$this->db->where('video.id_user', $user_id);
		}
		if($private != NULL){
			$this->db->where('video.status', $private);
		}
		$this->db->order_by('video.waktu_posting', 'DESC');
		if($limit != NULL){
			$this->db->limit($limit, $offset);
		}
		$query = $this->db->get();
		return $query->result_array();
	}
	function edit($id, $data){
		$this->db->where('id_video', $id);
		$this->db->update('video',$data);
	}
	function add($data){
		$this->db->insert('video',$data);
		return $this->db->insert_id();
	}
	function delete($id){
		$this->db->delete('video', array('id_video' => $id)); 
	}
}
?>